package viz.model.flare.decoders
{
	import viz.model.IDecodeable;
	import viz.model.flare.data.StateItem;
	import viz.model.flare.data.StateMap;


	public class Untyped2StateMap implements IDecodeable
	{
		private var o:Object;
		
		public function Untyped2StateMap( o:Object ):void{
			this.o = o;
		}
		
		public function decode( ):Object{
			var a:Array = parseIntoStates( o as Array );
			a = inseminate( a );
			return new StateMap( a );
		}
		
		public function parseIntoStates(tuples:Array):Array{
			var a:Array =[],
				state:StateItem,
				o:Object;
			for each (o in tuples) {
				a.push( new StateItem ( o ) );
			}
			return a;
		}
		
		private  function inseminate(states:Array):Array{
			var state:StateItem;
			for each (state in states) {
				state.inseminate(states);
			}
			return states;
		}
		
		
	}
	
}